/*
 * ElevatorDestinationComunicator.h
 *
 */

#ifndef ELEVATORDESTINATIONCOMUNICATOR_H_
#define ELEVATORDESTINATIONCOMUNICATOR_H_

#include <iostream>
#include <sys/types.h>
#include <vector>
#include "../common/Object.h"
#include "../common/Exception.h"
#include "../IPC/Semaphore.h"
#include "../IPC/SharedMemory.h"
#include "ApplicationCommon.h"

struct ElevatorStatus
{
	FloorIdentifier m_currentFloor;
//	bool  m_hasSpace;
	ElevatorStatusEnum m_currentDirection;
	bool hasNewCalls;
};

class ElevatorComunicator: public Object
{
static const int ELEVATOR_STATUS_INITIAL_KEY = 50;

public:
	ElevatorComunicator(int floorAmmount,char id,std::string keyGeneratorPath);

	virtual ~ElevatorComunicator();

	void setHallCalls(FloorIdentifierList floorList);

	FloorIdentifierList getHallCalls();

	void setAllCalls(FloorIdentifierList floorList);

	void setElevatorStatus(ElevatorStatus &status);

	void setMovementStatus(FloorIdentifier floorId, ElevatorStatusEnum direction);

	ElevatorStatus getElevatorStatus();

	FloorIdentifierList getAllCalls();

	void releaseResources();

private:
	char m_id;

    /**
     *
     */
    unsigned int m_floorAmmount;

    /**
     * Path de base, a partir del cual se crearan los pisos
     * y mecanismos de control.
     * Los pisos tendran un nombre de la forma:
     * "m_BaseFileName+numPiso"
     */
    std::string m_BaseFileName;

    /**
     *
     */
    bool m_IsRunning;

    /**
     *
     */
    SharedMemory<bool> m_callComunicator;

    /**
     *
     */
    SharedMemory<ElevatorStatus> m_elevatorStatusCommunicator;

    /**
     *
     */
    Semaphore m_semaphore;
};

#endif /* ELEVATORDESTINATIONCOMUNICATOR_H_ */
